clear all
set more off

cd "C:\Dropbox\Average_target_survey\replication_folder\workfiles"
use "step001 (through 11-16-2020)", clear

drop QJH9_*

gen QJH9_1=0
replace QJH9_1=1 if strpos(QJH9,"Keeping interest rates low to reduce the government")~=0 & QJH9~="" 
label var QJH9_1 "Fed objective: Keeping interest rates low to reduce the government’s cost of borrowing"

gen QJH9_2=0
replace QJH9_2=1 if strpos(QJH9,"Promoting maximum employment")~=0 & QJH9~="" 
label var QJH9_2 "Fed objective: Promoting maximum employment"

gen QJH9_3=0
replace QJH9_3=1 if strpos(QJH9,"Keeping stock prices high")~=0 & QJH9~="" 
label var QJH9_3 "Fed objective: Keeping stock prices high"

gen QJH9_4=0
replace QJH9_4=1 if strpos(QJH9,"Bailing out failing financial institutions")~=0 & QJH9~="" 
label var QJH9_4 "Fed objective: Bailing out failing financial institutions"

gen QJH9_5=0
replace QJH9_5=1 if strpos(QJH9,"Ensuring price stability")~=0 & QJH9~="" 
label var QJH9_5 "Fed objective: Ensuring price stability"

gen QJH9_6=0
replace QJH9_6=1 if strpos(QJH9,"Maintaining a strong dollar")~=0 & QJH9~="" 
label var QJH9_6 "Fed objective: Maintaining a strong dollar"

gen QJH9_7=0
replace QJH9_7=1 if strpos(QJH9,"Reducing economic inequality")~=0 & QJH9~="" 
label var QJH9_7 "Fed objective: Reducing economic inequality"

gen QJH9_8=0
replace QJH9_8=1 if strpos(QJH9,"Fighting climate change")~=0 & QJH9~="" 
label var QJH9_8 "Fed objective: Fighting climate change"

gen QJH9_9=0
replace QJH9_9=1 if strpos(QJH9,"Mitigating the economic consequences of racism")~=0 & QJH9~="" 
label var QJH9_9 "Fed objective: Mitigating the economic consequences of racism"

*** Redo QJH10_*
drop QJH10_*

gen QJH10_1=0
replace QJH10_1=1 if strpos(QJH10,"Keep the inflation rate as close as possible to a specific target at all times")~=0 & QJH10~="" 
label var QJH10_1 "Fed objective: Keep the inflation rate as close as possible to a specific target at all times"

gen QJH10_2=0 
replace QJH10_2=1 if strpos(QJH10,"Make inflation, on average, be approximately equal to a target rate")~=0 & QJH10~="" 
label var QJH10_2 "Fed objective: Make inflation, on average, be approximately equal to a target rate"

gen QJH10_3=0
replace QJH10_3=1 if strpos(QJH10,"Keep prices from rising over time")~=0 & QJH10~="" 
label var QJH10_3 "Fed objective: Keep prices from rising over time"

gen QJH10_4=0
replace QJH10_4=1 if strpos(QJH10,"Ensure inflation is sufficiently high to erode the value of government debt")~=0 & QJH10~="" 
label var QJH10_4 "Fed objective: Ensure inflation is sufficiently high to erode the value of government debt"

gen QJH10_5=0
replace QJH10_5=1 if strpos(QJH10,"Keep the inflation rate low enough to promote a strong dollar")~=0 & QJH10~="" 
label var QJH10_5 "Fed objective: Keep the inflation rate low enough to promote a strong dollar"

gen QJH10_6=0
replace QJH10_6=1 if strpos(QJH10,"None of the above")~=0 & QJH10~="" 
label var QJH10_6 "Fed objective: None of the above"

gen QJH10_7=0
replace QJH10_7=1 if strpos(QJH10,"know")~=0 & QJH10~="" 
label var QJH10_7 "Fed objective: I don’t know"

gen QJH10_8=0
replace QJH10_8=1 if QJH10=="" 
label var QJH10_8 "Fed objective: Missing"

gen QJH10_9 = QJH10_6+QJH10_7+QJH10_8
label var QJH10_9 "Fed objective: None of the above, I don't know, or Missing"

***collapse days when the sample size is small
gen start_day2=start_day1
recode start_day2 30/32=29
replace start_day2 = day_id+22 if start_day1 >= 33
replace start_day1 = day_id+25 if start_day1 >= 33

*** Have you heard any news about the Fed
gen QJH3_Yes=(QJH3==2) if QJH3~=. 
* tab start_day1 QJH3 [aw=weight], row nofreq

*** How many pieces of news about the Fed did you heard
tab start_day1 QJH4  [aw=weight] , row nofreq  
forvalues i=1(1)5 {
	gen QJH4_`i'=(QJH4==`i') if QJH4~=.
}
*** Where did you hear the news
* tabstat QJH5_1 QJH5_2 QJH5_3 QJH5_4 QJH5_5 QJH5_6 QJH5_7 QJH5_8 QJH5_9 [aw=weight], by(start_day1) format("%3.2f")

*** When did you hear the news
* tab start_day1 QJH6  [aw=weight] , row nofreq
forvalues i=0(1)6 {
	gen QJH6_`i'=(QJH6==`i') if QJH6~=.
}

*** What did you hear about the Fed
tabstat QJH7_1 QJH7_2 QJH7_3 QJH7_4 QJH7_5 QJH7_6 [aw=weight], by(start_day1) format("%3.2f")

*** Who did you hear about the Fed
tabstat QJH8_1 QJH8_2 QJH8_3 QJH8_4 QJH8_5 QJH8_6 [aw=weight], by(start_day1) format("%3.2f")

*** What is the Fed doing (objective)
tabstat QJH9_1 QJH9_2 QJH9_3 QJH9_4 QJH9_5 QJH9_6 QJH9_7 QJH9_8 [aw=weight], by(start_day1) format("%3.2f")

*** What does Fed in terms of prices?
tabstat QJH10_1 QJH10_2 QJH10_3 QJH10_4 QJH10_5 QJH10_9 [aw=weight], by(start_day1) format("%3.2f")

tempname 1
postfile `1'  str50 variable ///
	str50 E_statistic ///
	str12 E_aug26 ///
	str12 E_aug27AM ///
	str12 E_aug27PM ///
	str12 E_aug28 ///
	str12 E_aug29 ///
	str12 E_sep2 ///
	str12 E_sep9 ///
	str12 E_sep16 ///
	str12 E_sep23 ///
	str12 E_sep30 ///
	str12 E_oct7 ///
	str12 E_oct14 ///
	str12 E_oct21 ///
	str12 E_oct28 ///
	str12 E_nov4 ///
	str12 E_nov11 ///
	using "C:\Dropbox\Average_target_survey\replication_folder\outregs\AppendixTables_07_08.dta", replace every(1)
	
*** create dummy variables for each day	
foreach var in 26 28 29 30 31 32 33 34 35 36 37 38 39 40 {	
	gen aug`var'=(start_day2==`var') 
	gen _aug`var'=aug`var'*sqrt(weight)
}	

gen aug27A=(start_day2==27 & start_hour<12)
gen aug27B=(start_day2==27 & start_hour==12)
gen _aug27A=aug27A*sqrt(weight)
gen _aug27B=aug27B*sqrt(weight)

	
foreach var in ///
	QJH3_Yes /// Have you heard any news about the Fed
	 QJH4_2 QJH4_3 QJH4_4 QJH4_5 QJH4_1 /// How many pieces of news about the Fed did you heard
	QJH5_1 QJH5_2 QJH5_3 QJH5_4 QJH5_5 QJH5_6 QJH5_7 QJH5_8 QJH5_9  /// Where did you hear the news
	QJH6_0 QJH6_1 QJH6_2 QJH6_3 QJH6_4 QJH6_5 QJH6_6 /// When did you hear the news
	QJH7_1 QJH7_2 QJH7_3 QJH7_4 QJH7_5 QJH7_6  ///  What did you hear about the Fed
	QJH8_1 QJH8_2 QJH8_3 QJH8_4 QJH8_5 QJH8_6 /// Who did you hear about the Fed
	QJH9_1 QJH9_2 QJH9_3 QJH9_4 QJH9_5 QJH9_6 QJH9_7 QJH9_8 ///  What is the Fed doing (objective)
	QJH10_1 QJH10_2 QJH10_3 QJH10_4 QJH10_5 QJH10_9 /// What does Fed in terms of prices?
				{
		
			    
	
			***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			*** raw mean
			***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
			reg `var' aug26 aug27A aug27B aug28 aug29 aug30 aug31 aug32 aug33 aug34 aug35 aug36 aug37 aug38 aug39 aug40 [aw=weight], robust nocons
			test aug26 = aug27A
			local p1A=r(p)
			test aug26 = aug27B
			local p1B=r(p)			
			test aug26 = aug28
			local p2=r(p)
			test aug26 = aug29
			local p3=r(p)
			test aug26 = aug30
			local p4=r(p)		
			test aug26 = aug31
			local p5=r(p)		
			test aug26 = aug32
			local p6=r(p)		
			test aug26 = aug33
			local p7=r(p)	
			test aug26 = aug34
			local p8=r(p)	
			test aug26 = aug35
			local p9=r(p)	
			test aug26 = aug36
			local p10=r(p)	
			test aug26 = aug37
			local p11=r(p)	
			test aug26 = aug38
			local p12=r(p)	
			test aug26 = aug39
			local p13=r(p)	
			test aug26 = aug40
			local p14=r(p)	
			
			local M26_mean=string(_b[aug26],"%4.2f")
			local M27A_mean=string(_b[aug27A],"%4.2f")
			local M27B_mean=string(_b[aug27B],"%4.2f")
			local M28_mean=string(_b[aug28],"%4.2f")
			local M29_mean=string(_b[aug29],"%4.2f")
			local M30_mean=string(_b[aug30],"%4.2f")
			local M31_mean=string(_b[aug31],"%4.2f")
			local M32_mean=string(_b[aug32],"%4.2f")
			local M33_mean=string(_b[aug33],"%4.2f")
			local M34_mean=string(_b[aug34],"%4.2f")
			local M35_mean=string(_b[aug35],"%4.2f")
			local M36_mean=string(_b[aug36],"%4.2f")
			local M37_mean=string(_b[aug37],"%4.2f")
			local M38_mean=string(_b[aug38],"%4.2f")
			local M39_mean=string(_b[aug39],"%4.2f")
			local M40_mean=string(_b[aug40],"%4.2f")

			if abs(`p1A')<0.1 & `p1A'~=. local M27A_mean="`M27A_mean'" + "*"
			if abs(`p1B')<0.1 & `p1B'~=. local M27B_mean="`M27B_mean'" + "*"			
			if abs(`p2')<0.1 & `p2'~=. local M28_mean="`M28_mean'" + "*"
			if abs(`p3')<0.1 & `p3'~=. local M29_mean="`M29_mean'" + "*"
			if abs(`p4')<0.1 & `p4'~=. local M30_mean="`M30_mean'" + "*"
			if abs(`p5')<0.1 & `p5'~=. local M31_mean="`M31_mean'" + "*"
			if abs(`p6')<0.1 & `p6'~=. local M32_mean="`M32_mean'" + "*"
			if abs(`p7')<0.1 & `p7'~=. local M33_mean="`M33_mean'" + "*"
			if abs(`p8')<0.1 & `p8'~=. local M34_mean="`M34_mean'" + "*"
			if abs(`p9')<0.1 & `p9'~=. local M35_mean="`M35_mean'" + "*"
			if abs(`p10')<0.1 & `p10'~=. local M36_mean="`M36_mean'" + "*"
			if abs(`p11')<0.1 & `p11'~=. local M37_mean="`M37_mean'" + "*"
			if abs(`p12')<0.1 & `p12'~=. local M38_mean="`M38_mean'" + "*"
			if abs(`p13')<0.1 & `p13'~=. local M39_mean="`M39_mean'" + "*"
			if abs(`p14')<0.1 & `p14'~=. local M40_mean="`M40_mean'" + "*"
			
			if abs(`p1A')<0.05 & `p1A'~=. local M27A_mean="`M27A_mean'" + "*"
			if abs(`p1B')<0.05 & `p1B'~=. local M27B_mean="`M27B_mean'" + "*"
			if abs(`p2')<0.05 & `p2'~=. local M28_mean="`M28_mean'" + "*"
			if abs(`p3')<0.05 & `p3'~=. local M29_mean="`M29_mean'" + "*"
			if abs(`p4')<0.05 & `p4'~=. local M30_mean="`M30_mean'" + "*"
			if abs(`p5')<0.05 & `p5'~=. local M31_mean="`M31_mean'" + "*"
			if abs(`p6')<0.05 & `p6'~=. local M32_mean="`M32_mean'" + "*"
			if abs(`p7')<0.05 & `p7'~=. local M33_mean="`M33_mean'" + "*"
			if abs(`p8')<0.05 & `p8'~=. local M34_mean="`M34_mean'" + "*"
			if abs(`p9')<0.05 & `p9'~=. local M35_mean="`M35_mean'" + "*"
			if abs(`p10')<0.05 & `p10'~=. local M36_mean="`M36_mean'" + "*"
			if abs(`p11')<0.05 & `p11'~=. local M37_mean="`M37_mean'" + "*"
			if abs(`p12')<0.05 & `p12'~=. local M38_mean="`M38_mean'" + "*"
			if abs(`p13')<0.05 & `p13'~=. local M39_mean="`M39_mean'" + "*"
			if abs(`p14')<0.05 & `p14'~=. local M40_mean="`M40_mean'" + "*"
			
			if abs(`p1A')<0.01 & `p1A'~=. local M27A_mean="`M27A_mean'" + "*"
			if abs(`p1B')<0.01 & `p1B'~=. local M27B_mean="`M27B_mean'" + "*"
			if abs(`p2')<0.01 & `p2'~=. local M28_mean="`M28_mean'" + "*"
			if abs(`p3')<0.01 & `p3'~=. local M29_mean="`M29_mean'" + "*"	
			if abs(`p4')<0.01 & `p4'~=. local M30_mean="`M30_mean'" + "*"
			if abs(`p5')<0.01 & `p5'~=. local M31_mean="`M31_mean'" + "*"
			if abs(`p6')<0.01 & `p6'~=. local M32_mean="`M32_mean'" + "*"
			if abs(`p7')<0.01 & `p7'~=. local M33_mean="`M33_mean'" + "*"
			if abs(`p8')<0.01 & `p8'~=. local M34_mean="`M34_mean'" + "*"
			if abs(`p9')<0.01 & `p9'~=. local M35_mean="`M35_mean'" + "*"
			if abs(`p10')<0.01 & `p10'~=. local M36_mean="`M36_mean'" + "*"
			if abs(`p11')<0.01 & `p11'~=. local M37_mean="`M37_mean'" + "*"
			if abs(`p12')<0.01 & `p12'~=. local M38_mean="`M38_mean'" + "*"
			if abs(`p13')<0.01 & `p13'~=. local M39_mean="`M39_mean'" + "*"
			if abs(`p14')<0.01 & `p14'~=. local M40_mean="`M40_mean'" + "*"			
			
			***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			*** post results
			***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			post `1' ("`var'") ("raw mean")	("`M26_mean'") ("`M27A_mean'") ("`M27B_mean'") ("`M28_mean'")  ("`M29_mean'") ("`M30_mean'")  ("`M31_mean'") ("`M32_mean'") ("`M33_mean'") ("`M34_mean'") ("`M35_mean'") ("`M36_mean'") ("`M37_mean'") ("`M38_mean'") ("`M39_mean'") ("`M40_mean'")

}

postclose `1'
